#ifndef ELSLIDER_H
#define ELSLIDER_H

#include "../basic/elcomponent.h"

class QPropertyAnimation;


class ElSlider : public ElComponent
{
    Q_OBJECT
public:
    ElSlider(QWidget *parent = nullptr);

    int min() const;
    void setMin(int min);

    int max() const;
    void setMax(int max);

    int scope() const;
    void setScope(int min, int max);

    int value() const;
    void setValue(int value);
    void setRatio(qreal value);

    void setTooltip(ElTooltip *tooltip);
    ElTooltip *tooltip() const;

    bool stepStop() const;
    void setStepStop(bool newStepStop);

    QPair<qreal,qreal> sliderWidthScope() const;

signals:
    void sliderPressed();
    void sliderReleased();
    void sliderMoved();
    void valueChanged(int value);

protected:
    int _min{0};
    int _max{10};
    int _value{0};
    qreal _ratio{0.0};

    bool event(QEvent *e) override;
    void paintEvent(QPaintEvent *e) override;
    void mousePressEvent(QMouseEvent *e) override;
    void initPalette() override;


    class ElSliderCircle : public ElComponent
    {
    public:
        ElSliderCircle(ElSlider *parent);
        void updateTooltip(int value);

        qreal maxRadius() const;

        qreal radius() const;
        void setRadius(qreal newRadius);

    protected:
        void paintEvent(QPaintEvent *e) override;
        void enterEvent(QEnterEvent *e) override;
        void leaveEvent(QEvent *e) override;
        void mousePressEvent(QMouseEvent *e) override;
        void mouseReleaseEvent(QMouseEvent *e) override;
        void mouseMoveEvent(QMouseEvent *e) override;
        void initPalette() override;
        bool event(QEvent *e) override;


    private:
        QPropertyAnimation *_animation = nullptr;
        ElSlider *_slider = nullptr;
        bool _isHover = false;
        qreal _radius = 8;
    };
    ElSliderCircle *sliderCircle = nullptr;

private:
    qreal sliderWidth() const;

    Q_PROPERTY(int min READ min WRITE setMin)
    Q_PROPERTY(int max READ max WRITE setMax)
    Q_PROPERTY(int value READ value WRITE setValue)

    qreal _sliderheight = 8;
    bool _stepStop = false;
};

#endif // ELSLIDER_H
